<?php

/**
 * registro actions.
 *
 * @package    encuestas
 * @subpackage registro
 * @author     qualem
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class registroActions extends sfActions {

    /**
     * Executes index action
     *
     * @param sfRequest $request A request object
     */
    public function executeIndex(sfWebRequest $request) {
        //$this->forward('default', 'module');
        $this->form = new Registro();
    }

    public function executeSubmit(sfWebRequest $request) {
       $this->forward404Unless($request->isMethod('post'));
        $this->form = new Registro();
        $this->processForm($request, $this->form);
        $this->setTemplate('index');
    }
    public function executeSucessfull(){
     
    }

    public function processForm(sfWebRequest $request, sfForm $form) {
        $form->bind(
                $request->getParameter($form->getName()),
                $request->getFiles($form->getName())
        );


        if ($form->isValid()) {
            $persona = new EncPersona();
            $persona = $form->save();
            $encDireccion = new EncDireccion();
            $encDireccion->setCalle($form->getValue('calle') );
            $encDireccion->setPersonaId($persona->getId());
            $encDireccion->setNumero($form->getValue('numero'));
            $encDireccion->setColonia($form->getValue('colonia'));
            $encDireccion->setDelegacionMunicipio($form->getValue('delegacion_municipio'));
            $encDireccion->setReferencia($form->getValue('referencia'));
            $encDireccion->setEstado($form->getValue('estado'));
            $encDireccion->save();
            $parametros = array('nombre'=>$form->getValue('nombre'));
            $this->getUser()->singIn($persona);
            $this->redirect('registro/sucessfull');
        }
    }

}
